﻿using System;
using System.Collections.Generic;
using Opalis.QuickIntegrationKit;
using System.Text;
using Microsoft.Exchange.WebServices.Data;

namespace ExchangeMail
{
    [OpalisObject("Read Exchange Email")]
    public class ReadExchangeEmail
    {
        private MailSettings settings;

        [OpalisConfiguration]
        public MailSettings Settings
        {
            get { return settings; }
            set { settings = value; }
        }

        [OpalisOutput]
        public String NewMail
        {
            get
            {
                ExchangeService service = settings.MailServer;
                FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(settings.MaxEmails));                
                foreach (Item item in findResults.Items)
                {
                    return item.Subject;
                }
                return null;
            }
        }
    }
}
